package com.dhsc.service.impl.yykh;

import com.dhsc.domain.ywzx.yykh.XjgyLsVo;
import com.dhsc.domain.ywzx.yykh.XjgypdVo;
import com.dhsc.domain.ywzx.yykh.XjgytssxVo;
import com.dhsc.domain.yypt.LayuiTableVo;
import com.dhsc.domain.yypt.ResponseObject;
import com.dhsc.exception.MyException;
import com.dhsc.local.dao.yykh.IXjgypdDao;
import com.dhsc.local.dao.yykh.slrkp.ISlrkpDao;
import com.dhsc.service.yykh.IXjgypdService;
import com.dhsc.util.CommonUtil;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.page.PageMethod;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName: XjgypdServiceImpl
 * @Description: 星级柜员判定
 * @date: 2023/11/29 11:24
 * @author: jwj
 */
@Service
@Slf4j
public class XjgypdServiceImpl implements IXjgypdService {

    @Autowired
    private IXjgypdDao xjgypdDao;

    @Autowired
    private ISlrkpDao slrkpDao;

    @Override
    public LayuiTableVo queryXjgypdInfo(XjgypdVo xjgypdVo) {
        LayuiTableVo obj = new LayuiTableVo();
        try {
            List<XjgypdVo> list = xjgypdDao.queryXjgypdInfo(xjgypdVo);
            obj.setData(list);
            obj.setMsg("");
            obj.setCount(list.size());
            obj.setCode(0);
        }catch (Exception e){
            log.error("查询星级柜员评定信息出错",e);
            throw new MyException("查询星级柜员评定信息出错",e);
        }
        return obj;
    }

    @Override
    public LayuiTableVo queryYwslLs(XjgypdVo xjgypdVo) {
        LayuiTableVo obj = new LayuiTableVo();
        try {
            PageMethod.startPage(xjgypdVo.getPage(), xjgypdVo.getLimit());
            List<XjgyLsVo> list = null;
            if(xjgypdVo.getState().equals("1")){
                list = slrkpDao.querySlrkpYwslLs(xjgypdVo);
            }else{
                list = xjgypdDao.queryYwslLs(xjgypdVo);
            }
            PageInfo<XjgyLsVo> pageInfo = new PageInfo<>(list);
            obj.setData(list);
            obj.setMsg("");
            obj.setCount(pageInfo.getTotal());
            obj.setCode(0);
        }catch (Exception e){
            log.error("查询业务办理数量流水出错",e);
            throw new MyException("查询业务办理数量流水出错",e);
        }
        return obj;
    }

    @Override
    public LayuiTableVo queryYwzlLs(XjgypdVo xjgypdVo) {
        LayuiTableVo obj = new LayuiTableVo();
        try {
            PageMethod.startPage(xjgypdVo.getPage(), xjgypdVo.getLimit());
            List<XjgyLsVo> list = null;
            if(xjgypdVo.getState().equals("1")){
                list = slrkpDao.querySlrkpYwzlLs(xjgypdVo);
            }else{
                list = xjgypdDao.queryYwzlLs(xjgypdVo);
            }
            PageInfo<XjgyLsVo> pageInfo = new PageInfo<>(list);
            obj.setData(list);
            obj.setMsg("");
            obj.setCount(pageInfo.getTotal());
            obj.setCode(0);
        }catch (Exception e){
            log.error("查询业务办理质量流水出错",e);
            throw new MyException("查询业务办理质量流水出错",e);
        }
        return obj;
    }

    @Override
    public LayuiTableVo queryYwxlLs(XjgypdVo xjgypdVo) {
        LayuiTableVo obj = new LayuiTableVo();
        try {
            PageMethod.startPage(xjgypdVo.getPage(), xjgypdVo.getLimit());
            List<XjgyLsVo> list = null;
            if(xjgypdVo.getState().equals("1")){
                list = slrkpDao.querySlrkpYwxlLs(xjgypdVo);
            }else{
                list = xjgypdDao.queryYwxlLs(xjgypdVo);
            }
            PageInfo<XjgyLsVo> pageInfo = new PageInfo<>(list);
            obj.setData(list);
            obj.setMsg("");
            obj.setCount(pageInfo.getTotal());
            obj.setCode(0);
        }catch (Exception e){
            log.error("查询业务办理时长流水出错",e);
            throw new MyException("查询业务办理时长流水出错",e);
        }
        return obj;
    }

    @Override
    public LayuiTableVo queryKhpjLs(XjgypdVo xjgypdVo) {
        LayuiTableVo obj = new LayuiTableVo();
        try {
            PageMethod.startPage(xjgypdVo.getPage(), xjgypdVo.getLimit());
            List<XjgyLsVo> list = null;
            if(xjgypdVo.getState().equals("1")){
                list = slrkpDao.querySlrkpKhpjLs(xjgypdVo);
            }else{
                list = xjgypdDao.queryKhpjLs(xjgypdVo);
            }
            PageInfo<XjgyLsVo> pageInfo = new PageInfo<>(list);
            obj.setData(list);
            obj.setMsg("");
            obj.setCount(pageInfo.getTotal());
            obj.setCode(0);
        }catch (Exception e){
            log.error("查询客户评价流水出错",e);
            throw new MyException("查询客户评价流水出错",e);
        }
        return obj;
    }

    @Override
    public LayuiTableVo queryPxksLs(XjgypdVo xjgypdVo) {
        LayuiTableVo obj = new LayuiTableVo();
        try {
            PageMethod.startPage(xjgypdVo.getPage(), xjgypdVo.getLimit());
            List<XjgyLsVo> list = null;
            if(xjgypdVo.getState().equals("1")){
                list = slrkpDao.querySlrPxksLs(xjgypdVo);
            }else{
                list = xjgypdDao.queryPxksLs(xjgypdVo);
            }
            PageInfo<XjgyLsVo> pageInfo = new PageInfo<>(list);
            obj.setData(list);
            obj.setMsg("");
            obj.setCount(pageInfo.getTotal());
            obj.setCode(0);
        }catch (Exception e){
            log.error("查询培训考试流水出错",e);
            throw new MyException("查询培训考试流水出错",e);
        }
        return obj;
    }

    @Override
    public LayuiTableVo queryYwjsLs(XjgypdVo xjgypdVo) {
        LayuiTableVo obj = new LayuiTableVo();
        try {
            PageMethod.startPage(xjgypdVo.getPage(), xjgypdVo.getLimit());
            List<XjgyLsVo> list = xjgypdDao.queryYwjsLs(xjgypdVo);
            PageInfo<XjgyLsVo> pageInfo = new PageInfo<>(list);
            obj.setData(list);
            obj.setMsg("");
            obj.setCount(pageInfo.getTotal());
            obj.setCode(0);
        }catch (Exception e){
            log.error("查询业务竞赛流水出错",e);
            throw new MyException("查询业务竞赛流水出错",e);
        }
        return obj;
    }

    @Override
    public LayuiTableVo queryJyxcLs(XjgypdVo xjgypdVo) {
        LayuiTableVo obj = new LayuiTableVo();
        try {
            PageMethod.startPage(xjgypdVo.getPage(), xjgypdVo.getLimit());
            List<XjgyLsVo> list = xjgypdDao.queryJyxcLs(xjgypdVo);
            PageInfo<XjgyLsVo> pageInfo = new PageInfo<>(list);
            obj.setData(list);
            obj.setMsg("");
            obj.setCount(pageInfo.getTotal());
            obj.setCode(0);
        }catch (Exception e){
            log.error("查询建言献策流水出错",e);
            throw new MyException("查询建言献策流水出错",e);
        }
        return obj;
    }

    @Override
    public LayuiTableVo queryJxclLs(XjgypdVo xjgypdVo) {
        LayuiTableVo obj = new LayuiTableVo();
        try {
            PageMethod.startPage(xjgypdVo.getPage(), xjgypdVo.getLimit());
            List<XjgyLsVo> list = xjgypdDao.queryJxclLs(xjgypdVo);
            PageInfo<XjgyLsVo> pageInfo = new PageInfo<>(list);
            obj.setData(list);
            obj.setMsg("");
            obj.setCount(pageInfo.getTotal());
            obj.setCode(0);
        }catch (Exception e){
            log.error("查询降星处理流水出错",e);
            throw new MyException("查询降星处理流水出错",e);
        }
        return obj;
    }

    @Override
    public LayuiTableVo queryZgclLs(XjgypdVo xjgypdVo) {
        LayuiTableVo obj = new LayuiTableVo();
        try {
            PageMethod.startPage(xjgypdVo.getPage(), xjgypdVo.getLimit());
            List<XjgyLsVo> list = xjgypdDao.queryZgclLs(xjgypdVo);
            PageInfo<XjgyLsVo> pageInfo = new PageInfo<>(list);
            obj.setData(list);
            obj.setMsg("");
            obj.setCount(pageInfo.getTotal());
            obj.setCode(0);
        }catch (Exception e){
            log.error("查询取消资格流水出错",e);
            throw new MyException("查询取消资格流水出错",e);
        }
        return obj;
    }

    @Override
    public ResponseObject querySyjyr() {
        ResponseObject obj = new ResponseObject();
        try {
            String jyr = xjgypdDao.querySyrjyr(CommonUtil.getDateSystem());
            obj.setData(jyr);
            obj.setStatus(200);
        }catch (Exception e){
            log.error("查询上一交易日出错",e);
            throw new MyException("查询上一交易日出错");
        }
        return obj;
    }

    @Override
    public LayuiTableVo queryXjgytssxInfo(XjgytssxVo xjgytssxVo) {
        LayuiTableVo obj = new LayuiTableVo();
        try {
            PageMethod.startPage(xjgytssxVo.getPage(), xjgytssxVo.getLimit());
            List<XjgytssxVo> list = xjgypdDao.queryXjgytssxInfo(xjgytssxVo);
            PageInfo<XjgytssxVo> pageInfo = new PageInfo<>(list);
            obj.setData(list);
            obj.setMsg("");
            obj.setCount(pageInfo.getTotal());
            obj.setCode(0);
        }catch (Exception e){
            log.error("查询星级柜员特殊事项信息出错",e);
            throw new MyException("查询星级柜员特殊事项信息出错",e);
        }
        return obj;
    }

    @Override
    public ResponseObject queryTssxGyxl() {
        ResponseObject obj = new ResponseObject();
        try {
            List<XjgytssxVo> xjgytssxVos=xjgypdDao.queryTssxGyxl();
            obj.setData(xjgytssxVos);
            obj.setStatus(200);
        }catch (Exception e){
            log.error("查询柜员下拉取数出错",e);
            throw new MyException("查询柜员下拉取数出错");
        }
        return obj;
    }

    @Override
    public ResponseObject deleteXjgytssx(XjgytssxVo xjgytssxVo) {
        ResponseObject obj = new ResponseObject();
        try {
            if(!CommonUtil.isNotEmptyObj(xjgytssxVo.getBh())){
                obj.setData("编号不能为空！");
                obj.setStatus(500);
                return obj;
            }
            xjgypdDao.deleteXjgytssx(xjgytssxVo.getBh());
            obj.setStatus(200);
        }catch (Exception e){
            log.error("删除星级柜员特殊事项出错",e);
            throw new MyException("删除星级柜员特殊事项出错");
        }
        return obj;
    }

    @Override
    public ResponseObject insertXjgytssx(XjgytssxVo xjgytssxVo) {
        ResponseObject obj = new ResponseObject();
        try {
            //查询pdmc,pdlx,pddj,gyid是否存在相同记录
            int count=xjgypdDao.queryExistTssx(xjgytssxVo);
            if(count>0){
                obj.setStatus(500);
                obj.setMessage(" 新增失败！已存在该特殊事项！");
                return obj;
            }
            xjgypdDao.insertXjgytssx(xjgytssxVo);
            obj.setStatus(200);
        }catch (Exception e){
            log.error("新增星级柜员特殊事项出错",e);
            throw new MyException("新增星级柜员特殊事项出错");
        }
        return obj;
    }

    @Override
    public LayuiTableVo queryMydDfLs(XjgypdVo xjgypdVo) {
        LayuiTableVo obj = new LayuiTableVo();
        try {
            PageMethod.startPage(xjgypdVo.getPage(), xjgypdVo.getLimit());
            List<XjgyLsVo> list = xjgypdDao.queryMydDfLs(xjgypdVo);
            //查询翻译业务名称
            List<XjgyLsVo> listywmc = xjgypdDao.queryYwmc();
            //查询翻译发起渠道
            List<XjgyLsVo> listfqqd = xjgypdDao.queryFqqdmc();
            //查询翻译业务状态
            List<XjgyLsVo> listclzt = xjgypdDao.queryClztmc();
            //查询翻译是否评价
            List<XjgyLsVo> listsfpj = xjgypdDao.querySfpjmc();
            for (XjgyLsVo xjgyLsVo : list) {
                for (XjgyLsVo xjgyLsVo1 : listywmc) {
                    if(xjgyLsVo.getYwdm().equals(xjgyLsVo1.getYwdm())){
                        xjgyLsVo.setYwmc(xjgyLsVo1.getYwmc());
                    }
                }
                for (XjgyLsVo xjgyLsVo1 : listfqqd) {
                    if(xjgyLsVo.getFqqd() == xjgyLsVo1.getFqqd()){
                        xjgyLsVo.setFqqdmc(xjgyLsVo1.getFqqdmc());
                    }
                }
                for (XjgyLsVo xjgyLsVo1 : listclzt) {
                    if(xjgyLsVo.getClzt() == xjgyLsVo1.getClzt()){
                        xjgyLsVo.setClztmc(xjgyLsVo1.getClztmc());
                    }
                }
                for (XjgyLsVo xjgyLsVo1 : listsfpj) {
                    if(xjgyLsVo.getDcbz() == xjgyLsVo1.getDcbz()){
                        xjgyLsVo.setSfpjmc(xjgyLsVo1.getSfpjmc());
                    }
                }
            }
            PageInfo<XjgyLsVo> pageInfo = new PageInfo<>(list);
            obj.setData(list);
            obj.setMsg("");
            obj.setCount(pageInfo.getTotal());
            obj.setCode(0);
        }catch (Exception e){
            log.error("查询客户满意度流水出错",e);
            throw new MyException("查询客户满意度流水出错",e);
        }
        return obj;
    }
}
